package View;

import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.xml.soap.SAAJResult;
import javax.swing.JTable;
import javax.swing.JButton;

import java.awt.Font;
import java.awt.event.ActionEvent;

public class UpdateCustomerDeatilsView extends JFrame {
	 JTextField IdField;
	 JTextField firstNameField;
	 JComboBox AgeComboBox;
	 JComboBox CityComboBox;
	 JLabel lblPhoneNumber;
	 JTable table;
	 JTextField PhoneField;
	 JButton UpdateBtn;
	 JTextField lastNameField;
	 JButton BackBtn;
	
	public UpdateCustomerDeatilsView() {
		getContentPane().setLayout(null);
		
		this.setTitle("Update Customer");
		this.setSize(436, 365);
		
		JLabel lblCustumerId = new JLabel("CustomerID");
		lblCustumerId.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblCustumerId.setBounds(48, 39, 109, 20);
		getContentPane().add(lblCustumerId);
		
		IdField = new JTextField();
		IdField.setBounds(214, 40, 135, 20);
		getContentPane().add(IdField);
		IdField.setColumns(10);
		
		JLabel lblName = new JLabel("First Name");
		lblName.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblName.setBounds(48, 73, 79, 15);
		getContentPane().add(lblName);
		
		firstNameField = new JTextField();
		firstNameField.setColumns(10);
		firstNameField.setBounds(214, 71, 135, 20);
		getContentPane().add(firstNameField);
		
		JLabel lblLivingArea = new JLabel("Age");
		lblLivingArea.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblLivingArea.setBounds(48, 145, 72, 14);
		getContentPane().add(lblLivingArea);
		
		JLabel lblAg = new JLabel("City");
		lblAg.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblAg.setBounds(48, 181, 79, 17);
		getContentPane().add(lblAg);
		
		int x=2016-1900;
		String[] listOfElements = new String[x];

		for(int i=0;i<x;i++)
			listOfElements[i] = Integer.toString(i+1900);
			
		AgeComboBox = new JComboBox(listOfElements);
		AgeComboBox.setBounds(214, 144, 135, 18);
		AgeComboBox.addActionListener(AgeComboBox);
		getContentPane().add(AgeComboBox);
		
		lblPhoneNumber = new JLabel("Phone Number");
		lblPhoneNumber.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblPhoneNumber.setBounds(48, 224, 109, 16);
		getContentPane().add(lblPhoneNumber);
		
		table = new JTable();
		table.setBounds(222, 239, 141, -41);
		getContentPane().add(table);
		
		PhoneField = new JTextField();
		PhoneField.setBounds(214, 223, 135, 20);
		getContentPane().add(PhoneField);
		PhoneField.setColumns(10);
		
		UpdateBtn = new JButton("Add");
		UpdateBtn.setFont(new Font("Tahoma", Font.BOLD, 15));
		UpdateBtn.setBounds(239, 270, 135, 28);
		getContentPane().add(UpdateBtn);
		
		JLabel lblLastName = new JLabel("Last Name");
		lblLastName.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblLastName.setBounds(45, 111, 82, 14);
		getContentPane().add(lblLastName);
		
		lastNameField = new JTextField();
		lastNameField.setBounds(214, 109, 135, 20);
		getContentPane().add(lastNameField);
		lastNameField.setColumns(10);
		
		BackBtn = new JButton("Back");
	
		BackBtn.setFont(new Font("Tahoma", Font.BOLD, 15));
		BackBtn.setBounds(53, 270, 135, 28);
		getContentPane().add(BackBtn);
		
		 CityComboBox = new JComboBox();
		CityComboBox.setBounds(214, 180, 135, 20);
		getContentPane().add(CityComboBox);

		
		
		
	}
	
	public void addNewCustomerListener(ActionListener actionListener){
		UpdateBtn.addActionListener(actionListener);
		BackBtn.addActionListener(actionListener);
		
		
	}
	public void showWindow(){
		setVisible(true);
	}
	
	
	public void hideWindow(){
		setVisible(false);
	}
	
	public JButton getUpdateBtn()
	{
		return this.UpdateBtn;
	}
	public JButton getBackBtn()
	{
		return this.BackBtn;
	}
	
	public String getFirstName(){
		return firstNameField.getText();
	}
	
	/**
	 * @return LastNameField Text
	 */
	public String getlastName(){
		return lastNameField.getText();
	}
	

	
	/**
	 * @return AddressField Text 
	 */
	public String getCity(){
		return (String) CityComboBox.getSelectedItem();
	}
	
	/**
	 * @return PhoneField Text
	 */
	public String getPhone(){
		return PhoneField.getText();
	}
	
	/**
	 * @return ccnField Text 
	 */
	public String getID() {
		return IdField.getText();
	}
	
	public String getAge() {
			return (String) AgeComboBox.getSelectedItem();
		}
	/**
	 * 
	 */
	public void clearFirstName(){
		firstNameField.setText("");
	}
	
	/**
	 * 
	 */
	public void clearLastName(){
		lastNameField.setText("");
	}
	
	public  void clearAge() {
		AgeComboBox.setSelectedItem(" ");
		}
	
	public void clearCity(){
		CityComboBox.setSelectedItem(" ");
	}
	
	/**
	 * 
	 */
	public void clearPhone(){
		PhoneField.setText("");
	}

	public void clearFields(){
		PhoneField.setText("");
		AgeComboBox.setSelectedItem(" ");
		lastNameField.setText("");
		firstNameField.setText("");
		IdField.setText("");
		CityComboBox.setSelectedItem(" ");
			
		
	}
	/**
	 * @return UsernameField Text
	 */
	public void  setID(){
		IdField.setText("");
	}
}
